unit _fmMain;

interface

uses
  ValueList,
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TfmMain = class(TForm)
    Panel1: TPanel;
    btOpen: TButton;
    ScrollBox: TScrollBox;
    btClose: TButton;
    OpenDialog: TOpenDialog;
    Image: TImage;
    Timer: TTimer;
    procedure btOpenClick(Sender: TObject);
    procedure btCloseClick(Sender: TObject);
    procedure TimerTimer(Sender: TObject);
  private
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    procedure rp_VideoIsReady(AParams:TValueList);
  end;

var
  fmMain: TfmMain;

implementation

uses
  Core;

{$R *.dfm}

procedure TfmMain.btCloseClick(Sender: TObject);
begin
  TCore.Obj.Close;
end;

procedure TfmMain.btOpenClick(Sender: TObject);
begin
  if OpenDialog.Execute then begin
    try
      TCore.Obj.Open(OpenDialog.FileName);
    except
      on E : Exception do MessageDlg(E.Message, mtError, [mbOk], 0);
    end;
  end;
end;

constructor TfmMain.Create(AOwner: TComponent);
begin
  inherited;

  TCore.Obj.Initialize;

  TCore.Obj.View.Add(Self);
end;

destructor TfmMain.Destroy;
begin
  TCore.Obj.View.Remove(Self);

  inherited;
end;

procedure TfmMain.rp_VideoIsReady(AParams: TValueList);
begin
  if TCore.Obj.VideoOut.GetBitmap(Image.Picture.Bitmap) then Image.Repaint;
end;

procedure TfmMain.TimerTimer(Sender: TObject);
begin
  Timer.Enabled := false;
  try
    with TCore.Obj.Stream do
      Caption := Format('ez Player - %d / %d', [Position, Legnth]);
  finally
    Timer.Enabled := true;
  end;
end;

end.
